package com.demo.StringBufferTest;

import java.util.ArrayList;

/**
 * 一定要擅于利用索引
 * @author gy
 * @date 2022/3/13
 */
public class Price {
    private static String price;

    public static void main(String[] args) {
        price = "1111211111111111111.111";
        System.out.println(test(price));
    }
    public static StringBuffer test(String  price){
        StringBuffer buffer = new StringBuffer(price);
//        int i = buffer.lastIndexOf(".");
        for (int i = buffer.lastIndexOf(".")-3; i > 0; i-=3) {
            buffer =  buffer.insert(i,",");
        }
        return buffer;
    }
}

